home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / SOURCE / YEDIT.C < prev    next >
C/C++ Source or Header  |  1992-10-16  |  3KB  |  142 lines

  1. #include <stdio.h>
  2. #include "xlib.h"
  3. #include "xmouse.h"
  4. #include "mouse.spr"
  5.  
  6. main(int argc,char *argv[])
  7. {
  8.     int maxx;
  9.     int i,j,k;
  10.     int color = 1;
  11.     int ext = 0;
  12.     int w,h;
  13.     int x,y,b,v;
  14.     unsigned char bg = 0;
  15.     char fn[20],c;
  16.     FILE *fp;
  17.     unsigned char grid[16][16];
  18.  
  19.     if(argc != 2) exit();
  20.     maxx = x_set_mode(3,376);
  21.     x_mouse_init();
  22.  
  23.     strcpy(fn,argv[1]);
  24.     strcat(fn,".spr");
  25.     fp = fopen(fn,"r");
  26.  
  27.     if(fp)
  28.     {
  29.         while((c = fgetc(fp))!= '{');
  30.         fscanf(fp,"%d,%d,",&w,&h);
  31.     }
  32.  
  33.  
  34.     for(i=0;i<4;i++)
  35.     {
  36.         for(j=0;j<16;j++)
  37.         {
  38.             for(k=0;k<4;k++)
  39.             {
  40.                 if(fp)
  41.                 {
  42.                     fscanf(fp,"%d ,",&v);
  43.                     grid[k*4+i][j] = v;
  44.                 }
  45.                 else
  46.                     grid[k*4+i][j] = 0;
  47.  
  48.             }
  49.         }
  50.     }
  51.     if(fp)
  52.         fclose(fp);
  53.  
  54.     x_mouse_setim(mouse);
  55.     x_mouse_hide();
  56.     for(i=0;i<16;i++)
  57.     {
  58.         for(j=0;j<16;j++)
  59.         {
  60.             x_rect_fill(200+i*10,j*10,200+i*10+9,j*10+9,Page0_Offs,i*16+j);
  61.             x_rect_fill(i*10+2,j*10+2,i*10+9,j*10+9,Page0_Offs,grid[i][j]);
  62.         }
  63.     }
  64.     for(i=0;i<17;i++)
  65.     {
  66.         x_line(i*10,0,i*10,160,1,Page0_Offs);
  67.         x_line(0,i*10,160,i*10,1,Page0_Offs);
  68.     }
  69.     x_mouse_show();
  70.     while(!ext)
  71.     {
  72.         x_rect_fill(0,200,20,220,Page0_Offs,color);
  73.         while(!kbhit() && x_mouse_bstat == 0);
  74.         x = x_mouse_x;
  75.         y = x_mouse_y;
  76.         b = x_mouse_bstat;
  77.         if(x > 200 && x < 360 && y > 0 && y < 160)
  78.         {
  79.             if(b &1)
  80.                 color = ((x - 200)/10)*16+(y/10);
  81.             else
  82.                 bg = ((x - 200)/10)*16+(y/10);
  83.         }
  84.         else if(x < 160 && y < 160)
  85.         {
  86.             if(b & 1)
  87.             {
  88.                 x_mouse_hide();
  89.                 x_rect_fill(x/10*10+2,y/10*10+2,x/10*10+9,y/10*10+9,Page0_Offs,color);
  90.                 x_mouse_show();
  91.                 grid[x/10][y/10] = color;
  92.             }
  93.             else
  94.             {
  95.                 x_mouse_hide();
  96.                 x_rect_fill(x/10*10+2,y/10*10+2,x/10*10+9,y/10*10+9,Page0_Offs,0);
  97.                 x_mouse_show();
  98.                 grid[x/10][y/10] = 0;
  99.             }
  100.  
  101.         }
  102.         else if(b & 0x02)
  103.         {
  104.             ext = 1;
  105.         }
  106.         for(i=0;i<16;i++)
  107.         {
  108.             for(j=0;j<16;j++)
  109.             {
  110.                 if(grid[i][j])
  111.                     x_put_pix(100+i,200+j,Page0_Offs,grid[i][j]);
  112.                 else
  113.                     x_put_pix(100+i,200+j,Page0_Offs,bg);
  114.             }
  115.         }
  116.     }
  117.  
  118.     x_mouse_remove();
  119.     x_text_mode();
  120.  
  121.     strcpy(fn,argv[1]);
  122.     strcat(fn,".spr");
  123.     fp = fopen(fn,"w");
  124.     fprintf(fp,"unsigned char %s[] = {\n\t4,16,\n\t",argv[1]);
  125.     for(i=0;i<4;i++)
  126.     {
  127.         for(j=0;j<16;j++)
  128.         {
  129.             for(k=0;k<4;k++)
  130.             {
  131.                 fprintf(fp,"%d ",grid[k*4+i][j]);
  132.                 if(k!=3 || j!=15 || i!=3)
  133.                     fprintf(fp,",");
  134.  
  135.             }
  136.             fprintf(fp,"\n\t");
  137.         }
  138.     }
  139.     fprintf(fp,"};");
  140.     fclose(fp);
  141. }
  142.